import com.xiaowan.dao.UserMapper;
import com.xiaowan.entity.User;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

public class Test {
    public static void main(String[] args) {
//        ApplicationContext context = new ClassPathXmlApplicationContext("./resource/application-context.xml");
//        UserFather father = context.getBean(UserFather.class);
//        System.out.println(father.getFatherName());
//        UserController userController = context.getBean(UserController.class);
//        UserService userService = userController.getUserService();
//        userService.say("xiaowan");
//        ApplicationContext context = new ClassPathXmlApplicationContext("./resource/application-context.xml");
        /*测试MyBatis*/
        InputStream in =  Test.class.getResourceAsStream("resource/mybatis-cfg.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
        SqlSession session = factory.openSession();
        UserMapper userMapper = session.getMapper(UserMapper.class);
        User user = new User();
        user.setUserName("xiaowan");
        user.setPassword("123");
        user.setRealName("小万");
        userMapper.inserUser(user);
        session.commit();
        System.out.println(user.getId());
        session.close();

    }
}
